<?php 
if(eregi(basename(__FILE__),$_SERVER['REQUEST_URI'])) { die('Unauthorized Access Attempt'); }
function delDir($dirname) {
   if (is_dir($dirname)) {    //Operate on dirs only
       $result=array();
       if (substr($dirname,-1)!='/') {$dirname.='/';}    //Append slash if necessary
       $handle = opendir($dirname);
       while (false !== ($file = readdir($handle))) {
           if ($file!='.' && $file!= '..') {    //Ignore . and ..
               $path = $dirname.$file;
               if (is_dir($path)) {    //Recurse if subdir, Delete if file
                   $result=array_merge($result,rmdirtree($path));
               }else{
                   unlink($path);
                   $result[].=$path;
               }
           }
       }
       closedir($handle);
       rmdir($dirname);    //Remove dir
       $result[].=$dirname;
       return $result;    //Return array of deleted items
   }else{
       return false;    //Return false if attempting to operate on a file
   }
} // end DelDir function

function log_write($file, $output, $title) {
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date("d M Y - H:i:s");
    $string = 'IP: '.$ip;
    $header  = "---------[" . $title . "]----------------------------------------------------------------------------------\r\n";
    $wdata = $header;
    $wdata .= "<br />-&nbsp;[" . $date . "] - " . $string . "<br />\r\n";
    if(is_array($output)) {
        foreach($output as $line) {
             $wdata .= $line . "\r\n";
        }
    } else {
        $wdata .= $output . "\r\n";
    }
    $wdata .= str_repeat('-', (strlen($header)));
    $wdata .= "\r\n\r\n";
    if($handle = @fopen('logs/' . $file . '.log','a')) {
        fwrite($handle, $wdata);
        fclose($handle);
    }
    return;
} // end Log-write function

function mkfile($path){
$FileName = "$path";
$FileHandle = fopen($FileName, 'w') or dir("Failed to make file.. Please refresh");
fclose($FileHandle);
} // end mkfile function


//
// Scandir for PHP4
//
$PHP_ver = phpversion();
$var1 = explode(".", $PHP_ver);
$var2 = str_replace(" ", "_", $var1[0]);
$Ver_No = addslashes($var2);
if($Ver_No < 5) {
$sort = "asort";

function scandir($dir) { 
  global $sort; 
  global $file_file_count; 
  if (is_dir($dir)) { 
    $fd = @opendir($dir); 
    while (($part = @readdir($fd)) == true) { 
      clearstatcache(); 
      if ($part != "." && $part != "..") { 
        $file_array[] = $part; 
      } 
    } 
  if ($fd == true) { 
    closedir($fd); 
  } 
if(isset($file_array)) {
  if (is_array($file_array)) { 
    $sort($file_array); 
    $file_file_count = count($file_array); 
    return $file_array; 
  } else { 
    return false; 
  } 
  } else { 
    return false; 
  } 
  } else { 
    return false; 
  } 
} } // end scann function
?>